package com.easy.user.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.easy.common.bean.SysMenu;
import com.easy.common.service.IMenuService;
import com.easy.common.util.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("menu")
public class MenuController {
    @Autowired
    IMenuService menuService;
    @PostMapping("/")
    public ResultData insert(@RequestBody SysMenu menu){
        SysMenu result=menuService.insert(menu);
        return ResultData.success(result);
    }
    @PutMapping("/")
    public ResultData update(@RequestBody SysMenu menu){
        return ResultData.success(menuService.update(menu));
    }
    @DeleteMapping("/{id}")
    public ResultData delete(@PathVariable Integer id){
        int result=menuService.delete(id);
        if(result>=1){
            return ResultData.success();
        }else{
            return ResultData.fail();
        }
    }
    @GetMapping("/{id}")
    public ResultData getByID(@PathVariable Integer id){
        return ResultData.success(menuService.getByID(id));
    }
    @GetMapping("/page")
    public ResultData getListByPage(IPage page,@RequestBody SysMenu menu){
        IPage<SysMenu> data=menuService.getListByPage(page,menu);
        return ResultData.success(data);
    }
    @GetMapping("/list")
    public ResultData getList(SysMenu menu){
        List<SysMenu> data=menuService.getList(menu);
        return ResultData.success(data);
    }
}
